package cc.wsyw126.java.shuati;

import java.util.Scanner;

/**
 * Created by Administrator on 2017/9/6.
 */
public class FullPermutation {
    private static int count = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            char[] builder = s.toCharArray();
            FullPermutation(builder, 0);
            System.out.println("count = " + count);
            count = 0;
        }
    }

    private static void FullPermutation(char[] builder, int position) {
        if (position >= builder.length) {
            for (char c : builder) {
                System.out.print(c);
            }
            System.out.println();
            count++;
            return;
        }
        for (int j = position; j < builder.length; j++) {
            swap(builder, position, j);
            FullPermutation(builder, position + 1);
            swap(builder, position, j);
        }
    }

    private static void swap(char[] builder, int i, int j) {
        char c = builder[i];
        builder[i] = builder[j];
        builder[j] = c;
    }
}
